package com.bgs.service.impl;

import com.alibaba.fastjson.JSON;
import com.bgs.client.ThreeClient;
import com.bgs.common.R;
import com.bgs.pojo.Track;
import com.bgs.mapper.TrackMapper;
import com.bgs.pojo.vo.OrderDetail;
import com.bgs.pojo.vo.ThreeOrderDetail;
import com.bgs.pojo.vo.TrackThreeVoDetail;
import com.bgs.service.TrackService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 我的足迹 服务实现类
 * </p>
 *
 * @author Asia
 * @since 2021-09-14
 */
@Service
public class TrackServiceImpl extends ServiceImpl<TrackMapper, Track> implements TrackService {
    @Resource
    private TrackMapper trackMapper;
    @Autowired
    private RedisTemplate redisTemplate;
    @Resource
    private ThreeClient threeClient;

    @Override
    public R ThreeTrackRedis(Integer beforeUserId, Integer orderDetailId) {
        Track track = baseMapper.ThreeSelectOne(orderDetailId);
        if (track == null) {
            Integer i = trackMapper.ThreeTrackRedis(beforeUserId, orderDetailId);
        } else {
            Integer i = trackMapper.ThreeUpdate(orderDetailId);
        }
        return R.ok();
    }

    @Override
    public R ThreeSelectTrackRedis(String startTime, String endTime, Integer beforeUserId) {
        List<OrderDetail> list = trackMapper.ThreeSelectTrackRedis(startTime, endTime, beforeUserId);
        R data = threeClient.ThreeSelectDetail(list);
        return R.ok().data("data", data);
    }
}
